"""
标题为30字符添加日志
"""
from time import sleep
from selenium import webdriver
from selenium.webdriver.common.by import By
import unittest
#定位器


name_locator = (By.NAME, "name")
password_locator = (By.NAME, "password")
login_locator = (By.CSS_SELECTOR, "body > div.container > div > div.span4 > div > form > fieldset > input.btn.btn-primary")
xs_link_locator =(By.LINK_TEXT,"线索")
xs_table_locator = (By.CSS_SELECTOR,"#form1 > table > tbody")
xs_table_ck_element_locator = (By.LINK_TEXT,"查看")
xs_xsxq_gtrz_locator = (By.XPATH,'//*[@id="left_list"]/li[3]/a')
xs_xsxq_gtrz_add_locator = (By.XPATH,'//*[@id="tab2"]/div[1]/div[2]/a')
xs_xsxq_gtrz_add_bt_locator = (By.ID,"subject")
xs_xsxq_gtrz_add_nr_locator = (By.CSS_SELECTOR,"#dialog-log > form > table > tbody > tr:nth-child(3) > td:nth-child(2) > textarea")
xs_xsxq_gtrz_add_xclxsj_locator = (By.ID,"nextstep_time")
xs_xsxq_gtrz_add_xclxnr_locator = (By.ID,"nextstep")
xs_xsxq_gtrz_add_tj_locator = (By.XPATH,"/html/body/div[10]/div[2]/form/table/tbody/tr[5]/td[2]/input[1]")
#所需数据
name = "admin"
password = "123456"
bt = "123456789012345678901234567890"
nr = "合作愉快"
xclxsj = "2023-03-31 13:52"
xclxnr = "签订合同"

#操作
#打开浏览器
driver = webdriver.Chrome()
#最大化窗口
driver.maximize_window()
#进入悟空CRM登录界面
driver.get("http://192.168.1.25/crm/")
#输入用户名
driver.find_element(*name_locator).send_keys(name)
#输入密码
driver.find_element(*password_locator).send_keys(password)
#点击确定按钮
driver.find_element(*login_locator).click()
#点击线索按钮
driver.find_element(*xs_link_locator).click()
#找到线索列表
tabele = driver.find_element(*xs_table_locator)
#点击查看按钮
tabele.find_element(*xs_table_ck_element_locator).click()
#点击沟通日志
driver.find_element(*xs_xsxq_gtrz_locator).click()
sleep(1)
#点击添加按钮
driver.find_element(*xs_xsxq_gtrz_add_locator).click()
sleep(2)
#输入标题
driver.find_element(*xs_xsxq_gtrz_add_bt_locator).send_keys(bt)
#输入内容
driver.find_element(*xs_xsxq_gtrz_add_nr_locator).send_keys(nr)
#输入下次联系时间
driver.find_element(*xs_xsxq_gtrz_add_xclxsj_locator).send_keys(xclxsj)
#输入下次联系内容
driver.find_element(*xs_xsxq_gtrz_add_xclxnr_locator).send_keys(xclxnr)
#点击添加按钮
driver.find_element(*xs_xsxq_gtrz_add_tj_locator).click()
sleep(2)
#关闭浏览器
driver.quit()
if __name__ == '__main__':
    unittest.main()

